package com.oracle.em12c.command;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Hashtable;

import javax.net.ssl.HttpsURLConnection;

import com.google.gson.Gson;
import com.oracle.em12c.api.Element;
import com.oracle.em12c.api.NetworkInterface;
import com.oracle.em12c.api.VDC;


public class GetNetworkInterface implements ApiCommand {
	private HttpsURLConnection conn;
	public GetNetworkInterface(HttpsURLConnection conn) {
		this.conn = conn;
	}
	
	public Element execute(Hashtable params) throws IOException {
		System.out.println("Execute GetNetworkInterface");
		this.conn.setRequestProperty("Accept", "application/oracle.com.cloud.common.NetworkInterface+json");
		InputStream inputstream = this.conn.getInputStream();
		InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
		BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
		
		String string = null;
		String result = "";
		while ((string = bufferedreader.readLine()) != null) {
			result = result + string + "\n";
			//System.out.println(string);
	    }
		System.out.println(result);
		NetworkInterface e = new Gson().fromJson(result, NetworkInterface.class);
		return e;
	}
}
